package ch.unisi.inf.editor;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;


import javax.swing.*;

import ch.unisi.inf.engine.Image;

/**
 * 
 * @author matthias.eberli@lu.unisi.ch
 *
 */

public class EditorButtonFrame extends JPanel {
	
	private Image image;
	private ImagePanel imagePanel;
	private final ArrayList<EditorButtonFrameListener> listeners;
	
	
	private JButton closeButton;
    private final JButton saveButton;
    private final JButton infoButton;

    private List<Filter> filters;
    
	
	public EditorButtonFrame(Image image, final ImagePanel imagePanel){
		this.image = image;
		this.imagePanel = imagePanel;
		filters = createFilters();
		listeners = new ArrayList<EditorButtonFrameListener>();
	
		final SaveImgCommand saveImgCommand = new SaveImgCommand(image, this, imagePanel);
		final InfoCommand infoCommand = new InfoCommand(image, imagePanel, this);
		
		setLayout(new FlowLayout());
		
		infoButton = new JButton(infoCommand);
		add(infoButton);
		saveButton = new JButton(saveImgCommand);
		add(saveButton);
		
		
	}
    
    private void getInfo(ImageInfo info)
    {
        System.out.println(info.getName() + " :" + info.getInfo(image));
    }
    
    
    /**
     * Create and return a list with all the known filters.
     * @return The list of filters.
     */
    public List<Filter> createFilters()
    {
        List<Filter> filterList = new ArrayList<Filter>();
        filterList.add(new DarkerFilter("Darker"));
        filterList.add(new LighterFilter("Lighter"));
        filterList.add(new GrayScaleFilter("Gray Scale"));
        filterList.add(new InvertColorFilter("Invert"));
        filterList.add(new RotateColorsFilter("Switch colors"));
        filterList.add(new MirrorFilter("Mirror"));
        filterList.add(new SmoothFilter("Smooth"));
        filterList.add(new EdgeFilter("Edge"));
        
        return filterList;
    }   
	
	
	
	 //--- listener management
    public void addEditorButtonFrameListener(final EditorButtonFrameListener editorButtonFrameListener) {
        listeners.add(editorButtonFrameListener);
    }
    
    public void removeEditorButtonFrameListener(final ImageEditorFrameListener li) {
        listeners.remove(li);
    }
    
    private final void fireImageCharged() {
        for (final EditorButtonFrameListener li : listeners) {
            li.imageCharged();
        }
    }
}
